package priv.dajie.tzzq.test;

import priv.dajie.tzzq.bot.Bot;
import priv.dajie.tzzq.bot.BotManager;
import priv.dajie.tzzq.bot.buff.BuffBot;
import priv.dajie.tzzq.bot.c5.C5Bot;
import priv.dajie.tzzq.bot.model.*;
import priv.dajie.tzzq.bot.steam.SteamBot;
import priv.dajie.tzzq.common.ApplicationContextUnit;
import priv.dajie.tzzq.model.GoodsState;
import priv.dajie.tzzq.model.TradeStateItem;
import priv.dajie.tzzq.model.TradeStateItems;
import priv.dajie.tzzq.service.TradeService;
import priv.dajie.tzzq.spider.model.Platform;

import java.util.HashMap;

/**
 * @ClassName BugFix
 * @Description
 * @Author dajie
 * @Date 2019/10/9 11:31 下午
 * @Version V1.0
 **/
public class BugFix {
    public static void main(String[] args) {
        TradeService tradeService = (TradeService) ApplicationContextUnit.getInstance().getBean("tradeService");
        TradeStateItems tradeStateItems = tradeService.listTradeStateItem(GoodsState.PACKAGE);
        SteamBot steamBot = BotManager.getSteamBot();
        C5Bot c5Bot = BotManager.getC5Bot();
        BuffBot buffBot = BotManager.getBuffBot();
        SteamSellingItems sellingItems = steamBot.getSellingItems();
        SteamSellingItems confirmItems = steamBot.getConfirmItems();
        SteamPackItems pack = steamBot.getPack();
        HashMap<String, SteamPackItem> packMap = pack.getMap();
        Bot bot;
        r: for (TradeStateItem tradeStateItem : tradeStateItems){
            if(packMap.get(tradeStateItem.getSteamName()) == null){
                for(SteamSellingItem steamSellingItem : confirmItems){
                    if (steamSellingItem.getSteamName().equals(tradeStateItem.getSteamName())){
                        steamBot.unsell(steamSellingItem);
                        System.out.println("商品确认中："+steamSellingItem);
                        continue r;
                    }
                }
                for(SteamSellingItem steamSellingItem : sellingItems){
                    if (steamSellingItem.getSteamName().equals(tradeStateItem.getSteamName())){
                        steamBot.unsell(steamSellingItem);
                        System.out.println("商品出售中："+steamSellingItem);
                        continue;
                    }
                }

                if(tradeStateItem.getPlatform() == Platform.C5){
                    bot = c5Bot;
                }
                else{
                    bot = buffBot;
                }
                HashMap<String, PackItem> map = bot.getPack().getMap();
                if(map.get(tradeStateItem.getSteamName())!=null){
                    tradeService.updateState(tradeStateItem.getId(), GoodsState.WAIT);
                    System.out.println("在平台背包发现商品");
                }


                tradeService.updateState(tradeStateItem.getId(), GoodsState.UNKNOWN);
                System.out.println("状态未知："+ tradeStateItem);
            }
        }

    }
}
